import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/home/index.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: Home
  },
  {
    path: '/kind',
    name: 'kind',
    component: () => import('@/views/kind/index.vue')
  },
  {
    path: '/cart',
    name: 'cart',
    component: () => import('@/views/cart/index.vue')
  },
  {
    path: '/user',
    name: 'user',
    component: () => import('@/views/user/index.vue')
  },
  {
    path: '/detail/:proid', // 动态路由
    name: 'detail', // 命名路由
    component: () => import('@/views/detail/index.vue'), // 路由懒加载
    meta: { // 路由元信息
      show: true // 隐藏底部导航栏
    }
  },
  {
    path: '/register',
    name: 'register',
    redirect: '/register/step1', // 重定向到step1
    component: () => import('@/views/register/index.vue'),
    meta: {
      show: true // 隐藏底部导航栏
    },
    children: [
      {
        path: 'step1',
        name: 'Step1',
        component: () => import('@/views/register/step1.vue'),
        meta: {
          show: true // 隐藏底部导航栏
        }
      },
      {
        path: 'step2',
        name: 'Step2',
        component: () => import('@/views/register/step2.vue'),
        meta: {
          show: true // 隐藏底部导航栏
        }
      },
      {
        path: 'step3',
        name: 'Step3',
        component: () => import('@/views/register/step3.vue'),
        meta: {
          show: true // 隐藏底部导航栏
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      show: true
    }
  },
  {
    path: '/order/:time',
    name: 'order',
    component: () => import('@/views/order/index.vue'),
    meta: {
      show: true
    }
  },
  {
    path: '/order/:time/addAddress',
    name: 'addAddress',
    component: () => import('@/views/order/addAddress.vue'),
    meta: {
      show: true
    }
  },
  {
    path: '/order/:time/addAddress1',
    name: 'addAddress1',
    component: () => import('@/views/order/addAddress1.vue'),
    meta: {
      show: true
    }
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search/search.vue'),
    meta: {
      show: true
    }
  },
  {
    path: '*',
    component: () => import('@/views/error/notFound.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
